package controllers

import (
	"github.com/gin-gonic/gin"
	"github.com/zw2582/ginlib"
	"net/http"
	"strconv"
	"szxf/models"
	"szxf/vendors"
)

const txSign = "xs323kjsiu9sdgnlfgjhjlnlfskdjfsd"

//腾讯拦截中间件
func MiddleTxSign(c *gin.Context)  {
	this := ginlib.Context{c}
	sign := this.InputStr("sign")

	//腾讯专用
	if sign != txSign {
		this.JSON(http.StatusOK, gin.H{
			"uuid":ginlib.OrderNo(""),
			"code":models.RC_NO_ACCOUNT,
			"msg":models.RC_NO_ACCOUNT.Desc(),
			"data":nil,
		})
		this.Abort()
	}
	this.Next()
}

//IdCardBase 基础ocr校验
func IdCardBase(c *gin.Context)  {
	this := ginlib.Context{c}

	imgBase64 := this.InputStr("image")
	imgUrl := this.InputStr("url")

	data := vendors.VendorBaiduOcrDefault.IdcardBase(imgBase64, imgUrl, "font")

	this.JSON(http.StatusOK, gin.H{
		"uuid":ginlib.OrderNo(""),
		"code":models.RC_ID_YIZHI,
		"msg":"成功",
		"data":data,
	})
}

//IdCardBase 基础ocr校验
func IdCardPhoto(c *gin.Context)  {
	this := ginlib.Context{c}

	imgBase64 := this.InputStr("image")
	imgUrl := this.InputStr("url")

	data := vendors.VendorBaiduOcrDefault.IdcardPhoto(imgBase64, imgUrl, "font")

	this.JSON(http.StatusOK, gin.H{
		"uuid":ginlib.OrderNo(""),
		"code":models.RC_ID_YIZHI,
		"msg":"成功",
		"data":data,
	})
}

//IdCardBase 基础ocr校验
func IdCardRisk(c *gin.Context)  {
	this := ginlib.Context{c}

	imgBase64 := this.InputStr("image")
	imgUrl := this.InputStr("url")

	data := vendors.VendorBaiduOcrDefault.IdcardRisk(imgBase64, imgUrl, "font")

	this.JSON(http.StatusOK, gin.H{
		"uuid":ginlib.OrderNo(""),
		"code":models.RC_ID_YIZHI,
		"msg":"成功",
		"data":data,
	})
}

//IdCardBase 基础ocr校验
func IdCard(c *gin.Context)  {
	this := ginlib.Context{c}

	imgBase64 := this.InputStr("image")
	imgUrl := this.InputStr("url")
	detectRisk := this.InputStr("detect_risk")
	detectPhoto := this.InputStr("detect_photo")

	detect_risk,_ := strconv.ParseBool(detectRisk)
	detect_photo,_ := strconv.ParseBool(detectPhoto)

	data := vendors.VendorBaiduOcrDefault.IdcardUserDefine(imgBase64, imgUrl, "font", detect_risk, detect_photo)

	this.JSON(http.StatusOK, gin.H{
		"uuid":ginlib.OrderNo(""),
		"code":models.RC_ID_YIZHI,
		"msg":"成功",
		"data":data,
	})
}

func BankCard(c *gin.Context)  {
	this := ginlib.Context{c}

	imgBase64 := this.InputStr("image")

	data := vendors.VendorBaiduOcrDefault.BankCard(imgBase64)

	this.JSON(http.StatusOK, gin.H{
		"uuid":ginlib.OrderNo(""),
		"code":models.RC_ID_YIZHI,
		"msg":"成功",
		"data":data,
	})
}
